package com.ikingtech.platform.service.application.service;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.ikingtech.framework.sdk.utils.Tools;
import com.ikingtech.platform.service.application.entity.ApplicationAssignDO;
import com.ikingtech.platform.service.application.mapper.ApplicationAssignMapper;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @author tie yan
 */
@Service
public class ApplicationAssignService extends ServiceImpl<ApplicationAssignMapper, ApplicationAssignDO> {

    public List<ApplicationAssignDO> listByTenantCode(String tenantCode) {
        return this.list(Wrappers.<ApplicationAssignDO>lambdaQuery()
                .eq(Tools.Str.isNotBlank(tenantCode), ApplicationAssignDO::getTenantCode, tenantCode));
    }

    public void removeByAppCodeAndTenantCode(String appCode, String tenantCode) {
        this.remove(Wrappers.<ApplicationAssignDO>lambdaQuery()
                .eq(ApplicationAssignDO::getAppCode, appCode)
                .eq(Tools.Str.isNotBlank(tenantCode), ApplicationAssignDO::getTenantCode, tenantCode));
    }

    public void removeByAppCode(String appCode) {
        this.remove(Wrappers.<ApplicationAssignDO>lambdaQuery().eq(ApplicationAssignDO::getAppCode, appCode));
    }

    public ApplicationAssignDO getByAppCodeAndTenantCode(String appCode, String tenantCode) {
        return this.getOne(Wrappers.<ApplicationAssignDO>lambdaQuery().eq(ApplicationAssignDO::getAppCode, appCode)
                .eq(ApplicationAssignDO::getTenantCode, tenantCode));
    }

    public List<String> listAppCodeByTenantCode(String tenantCode) {
        return this.listObjs(Wrappers.<ApplicationAssignDO>lambdaQuery()
                .select(ApplicationAssignDO::getAppCode)
                .eq(ApplicationAssignDO::getTenantCode, tenantCode), String.class::cast);
    }
}
